package cn.mothin.frame.util;

public class UrlUtil {
	/**
	 * 检查URL是否包含指定的参数
	 * @param url
	 * @param name
	 * @return
	 */
	public static boolean containParam(String url, String name){
		if(url.contains("?"+name)||url.contains("&"+name)){
			return true;
		}
		return false;
	}
	
	public static String getParamValue(String url,String name){
		if(containParam(url,name)){
			String p = url.substring(url.indexOf('?') + 1);
			String params[] = p.split("&");
			for (String param : params) {
				String s = name + "=";
				if (param.startsWith(s)) {
					return param.replace(s, "");
				}
			}
		}
		return null;
	}
	
	/**
	 * 
	 * @param url
	 * @param name
	 * @param value
	 * @return
	 */
	public static String addParam(String url,String name,String value){
		if(url.contains("?")){
			url+="&";
		}else{
			url+="?";
		}
		return url+name+"="+value;
	}
}
